#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 3005;
using ull = unsigned long long;
const int P = 233;
const ull mask = mt19937_64(time(nullptr))();
int n, m;
string s;
int pos, tot;
vector<int> ch[N];
ull dp[N];
ull shift(ull x) {
  x ^= mask;
  x ^= x << 13;
  x ^= x >> 7;
  x ^= x << 17;
  x ^= mask;
  return x;
}
int build() {
  int u = ++tot;
  dp[u] = 1;
  ch[u].clear();
  while (pos < s.size() && s[pos] != '1') {
    pos++;
    int v = build();
    dp[u] += shift(dp[v]);
    ch[u].push_back(v);
    pos++;
  }
  return u;
}
ull get_hash() {
  cin >> s;
  tot = pos = 0;
  int rt = build();
  return dp[rt];
}
void solve() {
  ull ans = get_hash();
  ull ans2 = get_hash();
  bool res = ans == ans2;
  cout << (res ? "same" : "different") << endl;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}